﻿using Max.PH5_2008A.ShoppingCode.EFCore;
using Max.PH5_2008A.ShoppingCode.IRespository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Max.PH5_2008A.ShoppingCode.Respository
{
    public class BaseRespository<T> : IBaseRespository<T> where T : class,new()
    {
        PH52008ADbContext _context;

        public BaseRespository(PH52008ADbContext context)
        {
            _context = context;
        }

        public bool Delete(List<T> ts)
        {
            _context.Set<T>().RemoveRange(ts);
            int result = _context.SaveChanges();
            return result > 0;
        }

        public bool Insert(T t)
        {
            _context.Set<T>().Add(t);
            int result = _context.SaveChanges();
            return result > 0;
        }

        public IQueryable<T> Query()
        {
            IQueryable<T> result =  _context.Set<T>().AsQueryable();
            return result;
        }

        public bool Update(T t)
        {
            _context.Set<T>().Update(t);
            int result = _context.SaveChanges();
            return result > 0;
        }
    }
}
